<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<head>
	<meta charset="UTF-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>网站后台管理模版</title>
	<link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css"/>
	<link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css"/>
	<link href="http://www.jq22.com/jquery/bootstrap-3.3.4.css" rel="stylesheet">
</head>
<style >
	body {
		font: 500 14px 'roboto';
		color: #333;
		background-color: #fafafa;
	}
	a {
		text-decoration: none;
	}
	ul, ol, li {
		list-style: none;
		padding: 0;
		margin: 0;
	}
	#demo {
		width: 300px;
		margin: 150px auto;
	}
	p {
		margin: 0;
	}
	#dt {
		margin: 30px auto;
		height: 28px;
		width: 200px;
		padding: 0 6px;
		border: 1px solid #ccc;
		outline: none;
	}
</style>
<body>
<div class="layui-tab page-content-wrap">
	<ul class="layui-tab-title">
		<li class="layui-this">修改资料</li>
		<li>修改密码</li>
		<li>我的便签</li>
	</ul>
	<div class="layui-tab-content">
		<div class="layui-tab-item layui-show">
			<form class="layui-form"  style="width: 90%;padding-top: 20px;">

				<div class="layui-form-item">
					<label class="layui-form-label">ID：</label>
					<div class="layui-input-block">
						<input type="text"  disabled autocomplete="off" class="layui-input layui-disabled accountId" readonly>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">真实姓名：</label>
					<div class="layui-input-block">
						<input type="text"  disabled autocomplete="off" class="layui-input layui-disabled realName"  readonly>
					</div>
				</div>



				<div class="layui-form-item">
					<label class="layui-form-label">部门：</label>
					<div class="layui-input-block">
						<input type="text"  disabled autocomplete="off" class="layui-input layui-disabled  deptName"  readonly>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">职位：</label>
					<div class="layui-input-block">
						<input type="text"  disabled autocomplete="off" class="layui-input layui-disabled  roleName"  readonly>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">用户名：</label>
					<div class="layui-input-block">
						<input type="text"   autocomplete="off" class="layui-input  accountName" placeholder="请输入用户名">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">联系方式：</label>
					<div class="layui-input-block">
						<input type="text"  required  lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input accountTel" >
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label">毕业院校：</label>
					<div class="layui-input-block">
						<input type="text"  required  lay-verify="required" placeholder="请输入毕业院校" autocomplete="off" class="layui-input accountSchool" >
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">文凭：</label>
					<div class="layui-input-block">
						<input type="text"  required  lay-verify="required" placeholder="请输入文凭" autocomplete="off" class="layui-input accountEdu" >
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">地址：</label>
					<div class="layui-input-block">
						<input type="text"  required  lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input address" >
					</div>
				</div>



				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn layui-btn-normal uploadBtn3" type="button" >立即提交</button>
					</div>
				</div>

			</form>
		</div>
		<div class="layui-tab-item">
			<form class="layui-form" v style="width: 90%;padding-top: 20px;">
				<div class="layui-form-item">
					<label class="layui-form-label">用户名：</label>
					<div class="layui-input-block">
						<input type="text" name="accountname" disabled autocomplete="off" class="layui-input layui-disabled accountName" readonly>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">旧密码：</label>
					<div class="layui-input-block">
						<input type="password" name="password1" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input password1">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码：</label>
					<div class="layui-input-block">
						<input type="password" name="password2" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input password2" readonly>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">重复密码：</label>
					<div class="layui-input-block">
						<input type="password" name="password3" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input password3" readonly>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn uploadBtn2" type="button">立即提交</button>
					</div>
				</div>
			</form>
		</div>
		<div class="layui-tab-item">
			<form class="layui-form"  style="width: 90%;padding-top: 20px;">

				<div class="layui-form-item">
					<label class="layui-form-label">标题：</label>
					<div class="layui-input-block">
						<input type="text"  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input planTitle">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">内容：</label>
					<div id="editor">

					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn layui-btn-normal uploadBtn">立即提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
<script src="http://www.jq22.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://www.jq22.com/jquery/bootstrap-3.3.4.js"></script>
<script src="../../static/admin/js/wangEditor.min.js" ></script>
<%--<script src="../../static/admin/brithday/calendar.js" ></script>--%>
<%--<script src="../../static/admin/brithday/jquery.js" ></script>--%>
<script>




	//Demo
	layui.use(['form','element'], function(){
		var form = layui.form();
		var element = layui.element();
		form.render();
		//监听信息提交
		form.on('submit(adminInfo)', function(data){
			layer.msg(JSON.stringify(data.field));
			return false;
		});
		//监听密码提交
		form.on('submit(adminPassword)', function(data){
			layer.msg(JSON.stringify(data.field));
			return false;
		});
	});

	//设置富文本中的功能
	var E = window.wangEditor;
	var editor = new E('#editor');
	// 自定义菜单配置
	editor.customConfig.menus = [
		'head',  // 标题
		'bold',  // 粗体
		'fontSize',  // 字号
		'fontName',  // 字体
		'italic',  // 斜体
		'underline',  // 下划线
		'strikeThrough',  // 删除线
		'emoticon'  // 表情
	]
	editor.create();



	$(".uploadBtn").click(function(){
		//获取用户名
		var accountId="${sessionScope.accountMap.accountId}";
		//获取时间
		var date = new Date();
		//格式化时间
		var createTime = dateFormat("YY-mm-dd HH:MM:SS",date);
		//获得标题内容
		var planTitle = $(".planTitle").val();
		//获得正文
		var planContent = editor.txt.html();

		//添加便签
		$.ajax({
			async:true,
			url:"${pageContext.request.contextPath}/Plan/addPlanInfo",
			type:"post",
			data:{
				accountId:accountId,
				createTime:createTime,
				planTitle:planTitle,
				planContent:planContent

			},
			dataType:"json",
			success:function(result,status,xhr){

				if(result == "1"){
					alert("添加成功");

				}else {
					alert("添加失败");
				}


			},
			error:function(xhr,status,error){
				alert("异步请求失败!");
			}
		})
	})

	//格式化日期
	function dateFormat(fmt, date) {
		let ret;
		const opt = {
			"Y+": date.getFullYear().toString(),        // 年
			"m+": (date.getMonth() + 1).toString(),     // 月
			"d+": date.getDate().toString(),            // 日
			"H+": date.getHours().toString(),           // 时
			"M+": date.getMinutes().toString(),         // 分
			"S+": date.getSeconds().toString()          // 秒
			// 有其他格式化字符需求可以继续添加，必须转化成字符串
		};
		for (let k in opt) {
			ret = new RegExp("(" + k + ")").exec(fmt);
			if (ret) {
				fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
			};
		};
		return fmt;
	}

	//进入页面的时候从控制层中赋值到对应的框内
	$(document).ready(function(){
		//调用渲染函数 对用户界面进行渲染
		getInfoById()
	});

/*	//点击出生框后弹出日历
	$('#dd').calendar({
		trigger: '#dt',
		zIndex: 999,
		format: 'yyyy-mm-dd',
		onSelected: function (view, date, data) {
			console.log('event: onSelected')
		},
		onClose: function (view, date, data) {
			console.log('event: onClose')
			console.log('view:' + view)
			console.log('date:' + date)
			console.log('data:' + (data || 'None'));
		}
	});*/

	//修改密码页面
	//进入页面后对用户名赋值
	$(".accountName").val("${sessionScope.accountMap.accountName}");




	//修改密码时  需要先验证旧密码是否正确

	$(".password1").blur(function () {

		if($(".password1").val() != null || $(".password1").val().length != 0){
			$.ajax({
				async:true,
				url:"${pageContext.request.contextPath}/account/toMakeSure",
				type:"POST",
				data:{
						accountName:"${sessionScope.accountMap.accountName}",
					//accountName:"小李父斯基",
					password:$(".password1").val().trim()
				},
				dataType:"json",
				success:function(result,status,xhr){
					if (result != null) {
						$(".password2").prop("readOnly","");
						$(".password3").prop("readOnly","");
					}else {
						alert("请输入正确的密码！")
					}
				},
				error:function(xhr,status,error){
					alert("异步请求失败!");
				}
			});

		}


	});

	//点击修改按钮
	$(".uploadBtn2").click(function(){
		var password2 = $(".password2").val().trim();
		var password3 = $(".password3").val().trim();
		console.log(password2);
		console.log(password3);
		if (password2 == password3  && password3.length != 0  ){

			$.ajax({
				async:true,
				url:"${pageContext.request.contextPath}/account/motifyPwdByid",
				type:"POST",
				data:{
					//	accountId:"${sessionScope.accountMap.accountId}"
					accountId:"${sessionScope.accountMap.accountId}",
					password:password3
				},

				dataType:"json",
				success:function(result,status,xhr){
					if(result == "1"){
						alert("修改成功")

					}else {
						alert("修改失败");
					}
				},
				error:function(xhr,status,error){
					alert("异步请求失败!");
				}
			});

		}else {
			alert("请保证两次密码输入一致！！")
		}

	});
	//提交个人信息的修改
	$(".uploadBtn3").click(function () {
		var accountName =  $(".accountName").val();
		var accountTel = $(".accountTel").val();
		var accountSchool = $(".accountSchool").val();
		var accountEdu = $(".accountEdu").val();
		var address = $(".address").val();

		if(accountName.length != 0 &&
				accountTel.length != 0 &&
				accountSchool.length != 0 &&
				accountEdu.length != 0 &&
				address.length != 0 ){

			//如果输入框都不为空的时候提交ajax
			$.ajax({
				async:true,
				url:"${pageContext.request.contextPath}/account/motifyInfoByid",
				type:"POST",
				data:{
					accountId:"${sessionScope.accountMap.accountId}",
					accountName:accountName,
					accountTel:accountTel,
					accountSchool:accountSchool,
					accountEdu:accountEdu,
					address:address
				},
				dataType:"json",
				success:function(result,status,xhr){
					if(result == "1"){
						alert("修改成功")
						getInfoById()
					}else {
						alert("修改失败");
					}
				},
				error:function(xhr,status,error){
					alert("异步请求失败!");
				}
			});

		}else{
			alert("输入框不能为空！")
		}
	});


	//调用ajax对用户界面的用户信息进行渲染
	function getInfoById(){
		$.ajax({
			async:true,
			url:"${pageContext.request.contextPath}/account/getInfoById",
			type:"post",
			data:{
				accountId:"${sessionScope.accountMap.accountId}",
			},
			dataType:"json",
			success:function(result,status,xhr){
				$(".accountId").val(result.accountId);
				$(".realName").val(result.realName);
				$(".roleName").val(result.roleName);
				$(".deptName").val(result.deptName);
				$(".accountName").val(result.accountName);
				$(".accountTel").val(result.accountTel);
				$(".accountSchool").val(result.accountSchool);
				$(".accountEdu").val(result.accountEdu);
				$(".address").val(result.address);
			},
			error:function(xhr,status,error){
				alert("异步请求失败!");
			}
		})
	}

</script>
</body>
</jsp>
